package lab

// UniqBy 使用回调函数来判断是否有重复元素
func UniqBy[T any, K comparable](array []T, fn func(T, int, []T) K) []T {
	seen := make(map[K]bool)
	var result []T
	for i, v := range array {
		key := fn(v, i, array)
		if false == seen[key] {
			result = append(result, v)
			seen[key] = true
		}
	}
	return result
}
